#!/bin/bash

# 确保脚本以root权限运行
if [ "$EUID" -ne 0 ]; then
  echo "请以root权限运行此脚本."
  exit 1
fi

# 检查服务文件是否存在
if [ ! -f /home/umeko/comnode/scripts_robot/robotcom.service ]; then
  echo "错误: 找不到服务文件 /home/umeko/comnode/scripts_robot/robotcom.service."
  exit 1
fi

# 复制服务文件到systemd目录
cp /home/umeko/comnode/scripts_robot/robotcom.service /etc/systemd/system/

# 重新加载systemd守护进程
systemctl daemon-reload

# 启用并启动服务
systemctl enable robotcom.service
systemctl start robotcom.service

# 验证服务状态
if systemctl is-active --quiet robotcom.service; then
  echo "robotcom.service 已成功启动并运行."
else
  echo "错误: robotcom.service 启动失败，请检查日志."
  exit 1
fi
